<?php
/** 
 * Pharmacist_model
 * This class handles model work necessary for Pharmacist Crud and List operations 
 * 
 * @author Ray Nowell
 *	
 */ 
class Pharmacist_model extends MY_Model {

	function Pharmacist_model()
	{
		parent::MY_Model();
	}
	
	function Add_pharmacist($data)
	{
		$this->db->insert('pharmacist', $data);
		return;
	}
	
	function Update_pharmacist($data)
	{
		$this->db->where('pharmacist_id',element('pharmacist_id', $data));
		$this->db->where('facility_id',$this->facility_id);
		$this->db->update('pharmacist',$data);
	}
	
	function Delete_pharmacist()
	{
		$ret_val = $this->delete_record('pharmacist','pharmacist_id');
		return $ret_val;
	}
	/*
	 * Returns a list of current pharmacists
	 * @todo must filter by logged in user
	 */
	function get_pharmacist_list()
	{
		$select_fields = "pharmacist_id
										 ,last_name
										 ,first_name
										 ,CASE active WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE '' END AS Active";
		//Get the query results for the clinical pharmacists
		$this->db->select($select_fields, false);
		$this->db->from('pharmacist');
		$this->db->where('facility_id',$this->facility_id);
		$this->db->order_by('last_name, first_name');
		$query = $this->db->get();
				
		return $query->result_array();
	}

	/*
	 * Returns a single pharmacist record based on Cliincal Pharmacist Id passed 
	 */
	function get_pharmacist_id_record($pharmacist_id)
	{
		$query = $this->db->limit(1)->get_where('pharmacist', array('pharmacist_id' 	=> $pharmacist_id,
		 																'facility_id'	=>	$this->facility_id,
																	));
		 
		return $query->row();
	}
}

/* End of file pharmacist_model.php */
/* Location: ./system/application/models/pharmacist_model.php */